package com.edevp.common.core.util.security;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @author lean
 * @create 2022-07-08 4:55 PM
 **/
public class SecurityUtil {
	private static BCryptPasswordEncoder PASSWORD_ENCODER = new BCryptPasswordEncoder();

	/**
	 * 生成BCryptPasswordEncoder密码
     *
	 * @param password 密码
     * @return 加密字符串
     */
	public static String encryptPassword(String password)
	{
		return PASSWORD_ENCODER.encode(password);
	}

	/**
	 * 判断密码是否相同
	 *
	 * @param rawPassword 真实密码
	 * @param encodedPassword 加密后字符
	 * @return 结果
	 */
	public static boolean matchesPassword(String rawPassword, String encodedPassword)
	{
		return PASSWORD_ENCODER.matches(rawPassword, encodedPassword);
	}
}
